<!DOCTYPE html>
<html lang="zc-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        let arr = [1, 2, 3, 4, 5]
        let sum = 0
        function handleData(array, b) {
            for (let i = 0; i < array.length; i++) {
                sum += array[i]
            } if (b === true || b == null) {
                console.log(sum);
            } else if (b === false) {
                console.log(sum / array.length);
            }
            else {
                console.log('请输入正确的数');
            }

        }
        handleData(arr, true)
    </script>
</body>

</html>